<?php

/**
 * RoleInheritance storage class
 *
 * @author    Mon Zafra <monzee at gmail>
 * @copyright (c)2009 Mon Zafra
 * @license   http://monzee.wordpress.com/license New BSD
 * @version   $Id: RoleInheritance.php 38 2009-02-18 17:12:39Z monzee $
 */
class Admin_Array_RoleInheritance
{
    protected $_roleHeirarchy;

    public function __construct()
    {
        $this->_roleHeirarchy = array(
            array(
                'parent_id' => 'guest', // Guest
                'child_id'  => 'admin', // Administrator
            ),
            array(
                'parent_id' => 'guest', // Guest
                'child_id'  => 'member', // Member
            ),
            array(
                'parent_id' => 'member', // Member
                'child_id'  => 'author', // Author
            ),
            array(
                'parent_id' => 'member', // Member
                'child_id'  => 'mod', // Moderator
            ),
            array(
                'parent_id' => 'author', // Author
                'child_id'  => 'editor', // Editor
            ),
            array(
                'parent_id' => 'mod', // Moderator
                'child_id'  => 'editor', // Editor
            ),
        );
    }

    /**
     * Finds all rows where child_id == $childId, returns the parent ids
     * in an array
     *
     * @param string $childId
     * @return array
     */
    public function getParents($childId)
    {
        $map = $this->_roleHeirarchy;
        
        $ret = array();
        foreach ($map as $relation) {
            if ($relation['child_id'] == $childId) {
                $ret[] = $relation['parent_id'];
            }
        }

        return $ret;
    }

}
